<template>
  <div class="container">
    <div class="form">
      <div class="item">
        <div class="label">推荐人姓名</div>
        <input type="text"
               placeholder="请输入推荐人姓名"
               class="inp"
               maxlength="10"
               v-model="user_name">
      </div>
      <div class="item">
        <div class="label">推荐人手机</div>
        <input type="number"
               placeholder="请输入推荐人手机号码"
               class="inp"
               maxlength="11"
               v-model="user_tel">
      </div>
    </div>
    <div class="sub-btn"
         @click="sub()">
      保存
    </div>
  </div>
</template>

<script>
import common from '@/assets/js/mmk_common.js'
export default {
  data () {
    return {
      user_name: "",
      user_tel: ""
    };
  },
  methods: {
    sub () {
      if (this.user_name == "") {
        wx.showToast({
          title: "推荐人姓名不能为空", //提示的内容,
          icon: "none", //图标,
          duration: 2000, //延迟时间,
          mask: false //显示透明蒙层，防止触摸穿透,
        });
        return false;
      } else if (this.user_tel == "") {
        wx.showToast({
          title: "推荐人手机号不能为空", //提示的内容,
          icon: "none", //图标,
          duration: 2000, //延迟时间,
          mask: false //显示透明蒙层，防止触摸穿透,
        });
        return false;
      } else {
        wx.showLoading({
          title: "提交中...", //提示的内容,
          mask: true //显示透明蒙层，防止触摸穿透
        });
        common.fly_post("api/v4_5/set_recommend", {
          realname: this.user_name,
          username: this.user_tel
        }, result => {
          wx.hideLoading();
          let res = result.data;
          if (res.status_code == 0) {
            wx.showToast({
              title: "推荐人修改成功", //提示的内容,
              icon: "none", //图标,
              duration: 2000, //延迟时间,
              mask: false //显示透明蒙层，防止触摸穿透
            });
            wx.navigateBack({
              delta: 1 //返回的页面数，如果 delta 大于现有页面数，则返回到首页,
            });
          } else {
            wx.showToast({
              title: res.message, //提示的内容,
              icon: "none", //图标,
              duration: 2000, //延迟时间,
              mask: false //显示透明蒙层，防止触摸穿透
            });
          }
        })

      }
    }
  },
  onLoad () {
    wx.setNavigationBarTitle({
      title: "我的推荐人"
    });
  },
  onShow () {
    this.user_name = "";
    this.user_tel = "";
  }
};
</script>

<style lang="less" scoped>
.container {
  width: 100%;
  height: 100%;
  background: rgba(251, 251, 251, 1);
  padding-top: 10px;
  box-sizing: border-box;
  .form {
    width: 100%;
    min-height: 44px;
    background-color: #fff;
    .item {
      height: 44px;
      line-height: 44px;
      display: flex;
      padding-left: 15px;
      .label {
        font-size: 14px;
        font-family: "Regular";
        color: rgba(102, 102, 102, 1);
      }
      .inp {
        display: block;
        height: 100%;
        line-height: 44px;
        font-size: 14px;
        padding-left: 10px;
        flex: 1;
      }
    }
  }
  .sub-btn {
    width: 285px;
    height: 44px;
    line-height: 44px;
    text-align: center;
    background: linear-gradient(
      180deg,
      rgba(255, 152, 170, 1),
      rgba(246, 70, 101, 1)
    );
    border-radius: 24px;
    font-size: 14px;
    font-family: "Regular";
    color: rgba(255, 255, 255, 1);
    position: absolute;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
  }
}
</style>


